|
|
Kaveh Bazargan <kav### [at] delete_thisfocalimagecom> wrote:
> I think there is a fundamental point here about macro arguments which I
> need to learn. Why is segments zero in the line marked "//the back"?
> Any pointers welcome.
I don't know how much you know about programming, but #macros take their
parameters by reference.
That means that the macro does not get a copy of the thing you give it
as a parameter, but a reference, that is, a kind of "pointer" which points
to the original thing.
This means that if you give it an identifier, any modification the macro
makes to the parameter (even if it's done with #local) will be made to
the original identifier.
If you want to avoid a macro modifying its parameter, make a copy of it.
That is, instead of:
#macro Foo(param)
#while(param)
...
#local param = param-1;
#end
#end
do this:
#macro Foo(param)
#local index = param;
#while(index)
#local index = index-1;
#end
#end
(Btw, if you give an expression as parameter to a macro, a temporary
variable will be created and the reference will point to that, and
the temporary variable is destroyed after the macro call is over. That's
why it's ok to use expressions as parameters, eg Foo(a+b-1).
This has a curious side-effect that if you make a call like Foo((identifier))
that's an expression and not the identifier directly and thus the value of
the identifier will be copied to a temporary variable and the macro will not
modify the original identifier. However, it's better to make the macro
itself safe and not trust that the caller takes care.)
--
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}// - Warp -
Post a reply to this message
|
|